
from time import sleep
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium import webdriver
# 导入 Service 类（关键）
from selenium.webdriver.chrome.service import Service


#实例化对象：

service = Service(executable_path="E:\\python\\python38\\chromedriver.exe")
driver = webdriver.Chrome(service=service)
url = r"C:\Users\alg\PycharmProjects\UI自动化\注册实例.html"
driver.get(url)
action = ActionChains(driver)
driver.maximize_window()
sleep(5)

driver.find_element(By.CSS_SELECTOR,"#user").send_keys("admin")
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
driver.find_element(By.CSS_SELECTOR,"#tel").send_keys("130888888888")
driver.find_element(By.CSS_SELECTOR,"#email").send_keys("123@qq.com")


# 1.获取‘表单综合实例.html’当前窗口句柄
# 目的：判断只要不是当前窗口句柄，就一定是新的窗口句柄
current_handle = driver.current_window_handle
print("综合实例当前窗口句柄：", current_handle)

# 2.点击'注册A页面'链接
driver.find_element(By.PARTIAL_LINK_TEXT,"A网页").click()

# 3. 获取所有窗口句柄
handles = driver.window_handles
print("所有窗口句柄：", handles)

# 4. 获取注册A页面对应的窗口句柄，并切
# 判断 不是 '当前窗口句柄'
for i in handles:
    if i != current_handle:
        # 切换
        driver.switch_to.window(i)
        driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("admin")
        driver.find_element(By.CSS_SELECTOR, "#passwordA").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, "#telA").send_keys("130888888888")
        driver.find_element(By.CSS_SELECTOR, "#emailA").send_keys("123@qq.com")